import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileByteReader {
    public static void main(String[] args) {
        try {
            FileInputStream stream = new FileInputStream("stream.txt");

            /*char read = (char) stream.read();
            System.out.println("读取的字符是：" + read);
            read = (char) stream.read();
            System.out.println("读取的字符是：" + read);
            read = (char) stream.read();
            System.out.println("读取的字符是：" + read);*/

            /*byte[] temp = new byte[1024];
            // 将文件内容读取到输入，并返回读取的个数
            int length = stream.read(temp);
            // for (byte b : temp) {
            //     System.out.println((char) b);
            // }

            for (int i = 0; i < length; i++) {
                System.out.println((char) temp[i]);

            }*/

            byte[] temp = new byte[8];
            int length = 0;
            while ((length = stream.read(temp)) != -1){
                System.out.println(new String(temp, 0, length));
            }

            stream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
